<template>
  <div class="home-container">
    <div class="top-box">
      <div class="title">
        <p style="color: #555555; font-size: 32px; font-weight: 700">
          我的收藏
        </p>
      </div>
    </div>
    <div class="title2">
      <h1>全局方案收藏</h1>
    </div>
    <div class="commodity_ul">
      <div
        class="commodity_ul_li"
        v-for="(i, index) in this.commoditylist"
        :key="index"
        @click="router_id(i)"
        style="cursor: pointer"
      >
        <div class="commodity_ul_li_info">
          <div class="img">
            <img
              :src="'http://127.0.0.1:8000' + i.inspiration.images[0].image"
              alt=""
            />
          </div>
          <div style="display: flex; justify-content: space-between">
            <p>{{ i.inspiration.big_name }}</p>
            <p>➤</p>
          </div>
        </div>
      </div>
    </div>
    <el-empty
      v-if="this.Empty1"
      description="暂时还没有收藏的全局方案哦"
      :image-size="150"
    ></el-empty>
    <div class="title2">
      <h1>单品设计收藏</h1>
    </div>
    <div class="syleimgs">
      <div
        class="itmes"
        v-for="(i, index) in this.sylelist"
        :key="index"
        @click="goToDetail(i)"
      >
        <img :src="'http://127.0.0.1:8000' + i.style.images[0].image" alt="" />
      </div>
    </div>
    <el-empty
      v-if="this.Empty2"
      description="暂时还没有收藏的单品设计哦"
      :image-size="150"
    ></el-empty>
    <Footer/>
  </div>
</template>

<script>
import { getfavorites } from "@/api/inspiration.js";
import Footer from "../components/footer.vue";
export default {
  components: {
    Footer,
  },
  data() {
    return {
      commoditylist: [],
      sylelist: [],
      Empty1: false,
      Empty2: false,
    };
  },
  created() {
    this.getcollect();
  },
  methods: {
    getcollect() {
      getfavorites().then((res) => {
        this.commoditylist = res.inspiration_favorites;
        this.sylelist = res.style_favorites;
        if (this.commoditylist.length !== 0) {
          this.Empty1 = false;
        } else {
          this.Empty1 = true;
        }
        if (this.sylelist.length !== 0) {
          this.Empty2 = false;
        } else {
          this.Empty2 = true;
        }
      });
    },
    // 跳转详情页
    router_id(i) {
      this.$router.push({
        path: "/itemDetails",
        query: { id: i.inspiration.id },
      });
      console.log(i.id);
    },
    goToDetail(i) {
      this.$router.push({ path: "/productDetails", query: { id: i.style.id } });
      console.log(i.id);
    },
  },
};
</script>

<style lang="less" scoped>
.home-container {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  .top-box {
    display: flex;
    justify-content: center;
    align-items: center;
    .title {
      margin-top: 5px;
      border-bottom: 5px solid #f59a23;
      padding-bottom: 5px;
    }
  }

  .title2 {
    margin-top: 40px;
    margin-left: 5%;
  }
  .commodity_ul {
    display: grid;
    grid-template-columns: repeat(4, 1fr); /* 创建4列 */
    gap: 16px; /* 设置元素之间的间距 */
    padding: 0 8%;
    .commodity_ul_li {
      margin-top: 30px;
      .commodity_ul_li_info {
        display: flex;
        flex-direction: column;
        .img {
          img {
            max-width: 100%;
            object-fit: cover;
          }
        }
        p {
          margin-top: 20px;
          font-size: 18px;
          font-weight: 700;
          color: #333333;
        }
      }
    }
  }
  .commodity_ul_li .commodity_ul_li_info {
    overflow: hidden; /* 保持盒子大小不变，隐藏超出部分 */
  }

  .commodity_ul_li .img img {
    transition: transform 0.3s ease-in-out;
  }

  .commodity_ul_li .img img:hover {
    transform: scale(1.1); /* 放大图片 */
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    opacity: 0.9;
  }
  .syleimgs {
    width: 84%;
    padding-top: 30px;
    padding-left: 7%;
    column-count: 4; /* 控制列数 */
    column-gap: 1rem; /* 控制列之间的间距 */
    img {
      width: 100%;
      margin-bottom: 10px;
      display: block;
    }
  }
  .syleimgs .itmes {
    transition: transform 0.3s ease-in-out;
  }

  .syleimgs .itmes:hover {
    transform: scale(1.1);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.468)
  }
}
</style>
